package com.online.demo.service.impl;

import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.online.demo.service.IFastDFSService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;

@Service
public class FastDFSServiceImpl implements IFastDFSService {

//    @Resource
//    private FastFileStorageClient fastFileStorageClient;
//
//    @Value("base_url")
//    private String baseUrl;
//
//    // 上传文件
//    @Override
//    public String uploadFile(MultipartFile file) throws Exception{
//        String file_name = file.getOriginalFilename();
//
//        String extName = file_name.substring(file_name.lastIndexOf(".") + 1);
//
//        InputStream inputStream = file.getInputStream();
//
//        StorePath storePath = fastFileStorageClient.uploadFile(inputStream, file.getSize(), extName, null);
//
//        String fullPath = storePath.getFullPath();
//
//        String fileUrl = new StringBuilder(baseUrl).append(fullPath).toString();
//        System.out.println(fileUrl);
//
//        return fileUrl;
//    }
//
//    // 删除
//    @Override
//    public int deleteFile(String url) throws Exception {
//        fastFileStorageClient.deleteFile(url);
//        return  0;
//    }
//
//    // 修改 -- 先上传新的， 然后删除旧的， 返回新的url
//    @Override
//    public String updateFile(String url, MultipartFile file) throws Exception {
//        String fileUrl = uploadFile(file);
//        deleteFile(url);
//        return fileUrl;
//
//    }

}
